<template>
  <view class="submit_order">
    <!-- 适配状态栏 -->
    <view class="status_bar"></view>
    <!-- #ifndef MP-WEIXIN -->
    <view class="top_title flex-btw">
      <view>
        <text
          class="custom-icon custom-icon-jiantou2"
          @click="leftClick"
        ></text>
        <text class="name">确认订单</text>
      </view>
    </view>
    <!--  #endif -->
    <view class="flex flex_row_between padding address_info">
      <view class="flex" @click="editAdd">
        <image
          class="location"
          src="/static/images/address.png"
          style="width: 40rpx; height: 36rpx"
        ></image>
        <view class="address">
          <view>
            <view class="add eighteen bold">
              {{
                nowSelectInfo.address == "null"
                  ? "请添加收货地址"
                  : nowSelectInfo.address
              }}
            </view>
            <view class="name sixteen">
              {{ nowSelectInfo.name }} {{ nowSelectInfo.mobile }}
            </view>
          </view>

          <view
            class="name name_flex"
            @click="gopage"
            v-if="
              quadrants_setting.within_quadrants != '' &&
              quadrants_setting.quadrants_switch == 1
            "
          >
            <view style="margin-right: 20rpx">配送范围</view>
            <u-icon name="arrow-right" color="black" size="28"></u-icon>
          </view>

          <view
            class="caution twelve_font flex-middle"
            v-if="nowSelectInfo.address == null"
          >
            <view class="tip">温馨提示</view>
            <view class="">
              <view> 1. 请在( {{ limitTime }} )之间下单</view>
              <view v-if="quadrants_setting.within_quadrants != ''">
                2.
                {{ quadrants_setting.within_quadrants }}
              </view>
            </view>
          </view>
        </view>
      </view>
      <view @click="editAdd">
        <u-icon name="arrow-right" color="gray" size="20"></u-icon>
        <!--   @click="confirmd" -->
      </view>
    </view>

    <view class="goods">
      <!-- <view class="tit">商品</view> -->
      <div class="info-shop">
        <div class="info-shop-logo">
          <!-- <image
            :src="
              'https://copartner.oss-cn-beijing.aliyuncs.com/' + company_logo ||
              '/static/home_menu_image/shop-img.png'
            "
            style=""
          ></image> -->
          <image :src="'/static/home_menu_image/shop-img.png'" style=""></image>
        </div>
        <div class="info-shop-title">
          {{ this.companyInfo.company_name || "菜东家生鲜" }}
        </div>
        <div class="info-shop-icon"></div>
      </div>
      <div class="line"></div>
      <view class="goodsList">
        <view
          class="info-list"
          v-for="(item, index) in goodsList.slice(0, goodsListNum)"
          :key="index"
        >
          <!-- <view class="flex-middle"> -->
          <!-- <view class="imgs flex-middle">
              <img
                :src="item.img"
                class="img"
                style="width: 130rpx; height: 130rpx"
                mode="aspectFit"
              />
            </view>  -->
          <div class="info-list-image">
            <img class="img" :src="item.img" mode="aspectFit" alt="" />
          </div>

          <div class="info-list-shop">
            <div class="shop-top">
              <div class="shop-top-name">
                <span>{{ item.name }}</span>
                <span style="font-size: 20rpx; margin-left: 20rpx">{{
                  item.spu_name
                }}</span>
              </div>
              <span>× {{ Number(item.num) }}</span>
            </div>
            <div class="shop-meddle">
              <span>配送金额：￥{{ item.market_price }}</span>
              <!-- <span
                  >配送数量：{{
                    orderInfo.order_status == 2 || orderInfo.order_status == 3
                      ? Number(item.sort_num)
                      : 0
                  }}</span
                > -->
              <span> 配送数量：{{ item.num }}</span>
            </div>
            <div class="shop-bottom">备注:{{ item.note }}</div>
          </div>

          <!-- <view class="info">
              <view class="flex-middle"> -->
          <!-- 有is_origin_price代表是有活动价，但使用原价。 -->
          <!-- <text class="red" v-show="canshowprice"
                  >￥{{
                    item.is_origin_price == 1
                      ? item.market_price
                      : item.activity_price || item.market_price
                  }}/{{ item.unit }}</text
                >  -->
          <!-- <view class="flex wrap flex_col_center"> -->
          <!-- <text
                  v-for="(i, index) in item.datum"
                  :key="index"
                  class="red_tag"
                  >{{ i.title }}</text
                >
                <text class="yellow_tag" v-if="item.datum_activity">{{
                  item.datum_activity
                }}</text> 
         
              </view>
              <view
                >{{ item.goods_name }}
                <text class="spu">{{ item.spu_name }}</text>
              </view>
            </view>  -->
          <!-- </view> -->
          <!-- <text>× {{ item.num }}</text> -->
        </view>
      </view>
      <view
        v-if="goodsList.length > 1"
        @click="expendList('isexpend', 'goodsListNum', goodsList.length)"
        class="flex-center"
        style="margin-top: 14rpx"
      >
        <span v-if="!isexpend">剩余商品</span>
        <span v-else>点击收起</span>
        <u-icon name="arrow-up" v-if="isexpend"></u-icon>
        <u-icon name="arrow-down" v-else></u-icon>
        <!-- 共{{ goodsList.length }}件 -->
      </view>
      <div class="line"></div>
      <view class="goods" v-if="pointList.length > 0">
        <view class="tit">积分</view>
        <view class="goodsList">
          <view
            class="list flex-btw"
            v-for="(item, index) in pointList.slice(0, jfListNum)"
            :key="index"
          >
            <view class="flex-middle">
              <view class="imgs flex-middle">
                <!-- <image class="logo" v-if="showLogo==1" :src="logo" mode="aspectFit"></image> -->
                <img :src="item.img" class="img" mode="aspectFit" />
              </view>
              <view class="info">
                <view class="flex-middle">
                  <text class="red">{{ item.jf_points }}积分</text>
                </view>
                <view
                  >{{ item.goods_name }}
                  <text class="spu">{{ item.spu_name }}</text>
                </view>
              </view>
            </view>
            <text>× {{ item.num }}</text>
          </view>
        </view>
        <view
          @click="expendList('isexpend_jf', 'jfListNum', pointList.length)"
          class="flex-center"
          style="margin-top: 14rpx"
        >
          <u-icon name="arrow-up" v-if="isexpend_jf"></u-icon>
          <u-icon name="arrow-down" v-else></u-icon>
          共{{ pointList.length }}件
        </view>
      </view>
      <view class="goods" v-if="zpList.length > 0">
        <view class="tit">赠品</view>
        <view class="goodsList">
          <view
            class="list flex-btw"
            v-for="(item, index) in zpList.slice(0, zpListNum)"
            :key="index"
          >
            <view class="flex-middle">
              <view class="imgs flex-middle">
                <!-- <image class="logo" v-if="showLogo==1" :src="logo" mode="aspectFit"></image> -->
                <img :src="item.img" class="img" mode="aspectFit" />
              </view>
              <view class="info">
                <view class="flex-middle">
                  <!-- <text class="red">{{item.jf_zps}}积分</text> -->
                </view>
                <view
                  >{{ item.goods_name }}【{{ item.spu_name }}】
                  <text class="yellow_tag">赠品</text>
                </view>
              </view>
            </view>
            <text>× {{ item.num }}</text>
          </view>
        </view>
        <view
          @click="expendList('isexpend_zp', 'zpListNum', zpList.length)"
          class="flex-center"
          style="margin-top: 14rpx"
        >
          <u-icon name="arrow-up" v-if="isexpend_zp"></u-icon>
          <u-icon name="arrow-down" v-else></u-icon>
          共{{ zpList.length }}件
        </view>
      </view>
      <view class="select padding sixteen">
        <picker mode="date" :start="startDay" @change="selectDate">
          <view class="flex-btw" style="margin-bottom: 48rpx">
            <text>配送日期</text>
            <view class="uni-list-cell-db flex-middle">
              <view class="uni-input">{{ sendDate }}</view>
              <u-icon name="arrow-right" color="gray" size="20"></u-icon>
            </view>
          </view>
        </picker>
        <view @click="showTime = true">
          <text>配送时间</text>
          <view class="flex-middle">
            <text style="color: #191919">{{ sendTimeName }}</text>
            <u-select
              v-model="showTime"
              mode="single-column"
              :list="send_time"
              value-name="id"
              label-name="time"
              @confirm="selectTime"
            ></u-select>
            <u-icon name="arrow-right" color="gray" size="20"></u-icon>
          </view>
        </view>
        <view>
          <text>商品总金额</text>
          <view>
            <text style="color: #191919"
              >￥{{ Number(money.sub_money).toFixed(2) }}</text
            >
          </view>
        </view>

        <!-- <view>
				<text>满减</text>
				<view>
					<text style="color:#191919;">- ￥{{ Number(money.full_reduction_money).toFixed(2) }}</text>
				</view>
			</view> -->

        <!-- <view @click="toChooseCoupon">
				<text>优惠券</text>
				<view class="flex-middle">
					<text style="color:#191919" v-if="couponInfo.coup_id == 0">暂无可用</text>
					<text style="color:#4FA388" v-else>- ￥{{ couponInfo.coupon_now.coupons.money }}</text>
					<u-icon name="arrow-right" color="gray" size="20"></u-icon>
				</view>
			</view> -->

        <!-- <view>
				<text>运费</text> 
				<view>
					<text>￥{{ Number(money.delivery_fee).toFixed(2) }}<text v-if="money.fare_delivery_fee != '0.00'">(满￥{{
						Number(money.fare_delivery_fee).toFixed(2) }}免运费)</text></text>
				</view>
			</view> -->

        <!-- <view>
				<text>差额</text>
				<view>
					<text>￥{{ Number(money.balance).toFixed(2) }}</text>
				</view>
			</view> -->

        <view>
          <text>起送价</text>
          <view>
            <text>￥{{ Number(money.starting_price).toFixed(2) }}</text>
          </view>
        </view>

        <view>
          <text>下单金额</text>
          <view>
            <text style="color: #191919"
              >￥{{ Number(money.should_money).toFixed(2) }}</text
            >
          </view>
        </view>

        <view v-if="money.points > 0">
          <text>积分</text>
          <view>
            <text style="color: #191919">- {{ money.points }}</text>
          </view>
        </view>

        <!-- <view class="flex flex_row_between child" @click="showPay=true"> -->
        <view @click="showPay = true" class="payments">
          <text>支付方式</text>
          <view class="flex-middle">
            <picker
              @change="selectPay"
              mode="selector"
              :range="payList"
              :value="pay.index"
              range-key="label"
            >
              <text style="color: #191919">{{ pay.name }}</text>
              <u-icon name="arrow-right" color="gray" size="20"></u-icon>
            </picker>
            <!-- <u-select v-model="showPay" mode="single-column" :list="payList" @confirm="selectPay"></u-select> -->
          </view>
        </view>
      </view>
    </view>
    <view class="remark">
      <text>订单备注</text>
      <textarea
        @input="noteAction"
        placeholder="请留下你的备注"
        auto-height
      ></textarea>
    </view>
    <view
      class="infomation"
      v-if="
        this.pay.name == '货到付款' && overdue.overdue_status != 0
          ? true
          : false
      "
    >
      <view :class="[{ error: overdue.overdue_status == 2 }, ' info']">{{
        overdue.info
      }}</view>
      <view :class="[{ error: credit.credit_status == 2 }, ' info']">{{
        credit.info
      }}</view>
    </view>
    <view
      class="infomation"
      v-if="
        this.pay.name == '货到付款' && credit.credit_status != 0 ? true : false
      "
    >
      <view :class="[{ error: overdue.overdue_status == 2 }, ' info']">{{
        overdue.info
      }}</view>
      <view :class="[{ error: credit.credit_status == 2 }, ' info']">{{
        credit.info
      }}</view>
    </view>
    <view class="submit flex flex_col_center">
      <view class="sixteen flex-center">
        <!-- <text class="bold">实付金额：</text> -->
        <span>共{{ goodsList.length }}件，合计：</span>
        <view class="flex-column" style="align-items: flex-end">
          <text class="red_font"
            >￥{{ Number(money.total_money).toFixed(2) }}</text
          >
          <text
            v-if="money.points > 0"
            class="red_font"
            style="font-size: 24rpx"
            >积分 -{{ money.points }}</text
          >
        </view>
      </view>
      <view class="order twelve_font" @click="submit"> 提交订单 </view>
    </view>
    <u-mask :show="showMask"></u-mask>
  </view>
</template>

<script>
import { jsonp } from "vue-jsonp";
import { mapState } from "vuex";
let app = getApp();
import { $https } from "@/static/js/request.js";
import MixinShowprice from "@/static/js/mixinshowprice.js";
export default {
  data() {
    return {
      showMask: false,
      logo: "",
      showLogo: 0,
      showChild: false, //选择子账户弹窗
      childList: [],
      showPay: false, //选择支付方式弹窗
      payList: [],
      pay: {
        name: "",
        id: null,
        index: 0,
      },
      limitTime: null,
      showTime: false,
      //主账号信息：用户地址、收货人、号码
      info: {
        address: null,
        name: null,
        mobile: null,
        id: null,
      },
      nowSelectInfo: {}, //当前选择的账号地址信息
      //当前选择的账号（用于选择器显示）
      child: {
        id: null,
        name: "",
      },
      //各个select默认选中的值
      // defaultValue:{
      // 	pay:[],
      // },
      sendDate: null, //选择的配送日期
      // sendDateM:null,	//配送日期转毫秒
      send_time: [], //配送时间列表
      sendTimeId: null, //选择的配送时间id
      sendTimeName: "请选择配送时间", //选择的配送时间
      note: "", //备注
      goodsId: null, //商品id
      money: {}, //金钱相关（差额，小计，合计，积分，运费）
      couponInfo: {
        coupon_now: {
          coupons: {},
        },
      }, //优惠券相关

      isexpend: false,
      goodsList: [],
      goodsListNum: 1,
      isexpend_jf: false,
      pointList: [], //积分商品
      jfListNum: 1,
      isexpend_zp: false,
      zpList: [], //赠品
      zpListNum: 1,

      overdue: {}, //账期
      credit: {}, //信用金
      backDay: 0, //开始日期回退天数
      startDay: this.tomorrow(),
      quadrants_setting: {},

      company_id: null,

      longitude: null,
      latitude: null,
    };
  },
  computed: {
    ...mapState(["companyInfo"]),
  },
  mixins: [MixinShowprice],
  onReady() {
    getApp().setTitle();
  },
  onLoad(options) {
    console.log("options", options, "this.companyInfo", this.companyInfo);
    this.sendDate = this.tomorrow();
    this.goodsId = JSON.parse(options.ids);
    this.company_id = this.companyInfo.supplier_id;
    console.log("111", this.goodsId);
    this.logo = uni.getStorageSync("logo");
    this.showLogo = uni.getStorageSync("showLogo");
  },
  onShow() {
    uni.$once("selectCoupon", (data) => {
      this.findCoupon(data.id);
    });
    this.getData();
  },

  methods: {
    getData() {
      // let company_id = this.companyInfo.supplier_id;
      // let goodsIds = this.goodsId.map(item => item.id)
      $https(
        "POST",
        `countCart?company_id=${this.company_id}`,
        {
          cart_ids: [...this.goodsId],
        },
        (res) => {
          let data = res.data.data;
          console.log("data", res);
          if (res.data.errcode == 0) {
            this.money = {
              // pay_type_now: 1在线支付，0货到付款
              balance: data.balance,
              total_money: data.total_money,
              sub_money: data.sub_money,
              delivery_fee: data.delivery_fee, //运费
              fare_delivery_fee: data.fare_delivery_fee, //满多少免运费
              starting_price: data.starting_price, //起送
              should_money: data.should_money, //支付金额（小于起送不能提交订单
              points: data.points, //积分
              full_reduction_money: data.full_reduction_money, //满减
            };
            this.filterGoods(data.list);
            this.zpList = data.zp_list;
            //优惠券相关
            this.couponInfo = {
              coup_id: data.coup_id,
              coupons_list: data.coupons_list,
            };
            this.findCoupon(data.coup_id, true);
            this.backDay = data.send_time_back_days; //开始日期回退天数
            this.startDay = this.tomorrow(this.backDay);
            this.send_time = data.send_time.map((i) => {
              return {
                id: i.id,
                time: `${i.start_time} ~ ${i.end_time}`,
              };
            });
            this.send_time.unshift({
              id: 0,
              // time:'00:00:00 ~ 24:00:00'
              time: "不限",
            });
            this.sendTimeName = this.send_time[0].time;
            this.sendTimeId = this.send_time[0].id;
            this.limitTime = `${data.allowed_time.open_time} ~ ${data.allowed_time.end_time}`;
            let address_detail = data.address.detail ? data.address.detail : "";
            this.latitude = data.address.lat || null;
            this.longitude = data.address.lng || null;
            this.info = {
              address: data.address.address_name + address_detail,
              name: data.address.name,
              mobile: data.address.mobile,
              user_id: data.address.user_id,
            };
            this.nowSelectInfo = JSON.parse(JSON.stringify(this.info));
            //支持的支付方式
            this.pay = {
              type: data.pay_type,
              type_now: data.pay_type_now,
            };
            this.quadrants_setting = data.quadrants_setting;
            if (data.pay_type == 1) {
              this.payList = [
                {
                  label: "在线支付",
                  value: 1,
                },
              ];
            } else if (data.pay_type == 0) {
              this.payList = [
                {
                  label: "货到付款",
                  value: 0,
                },
              ];
            } else {
              this.payList = [
                {
                  label: "在线支付",
                  value: 1,
                },
                {
                  label: "货到付款",
                  value: 0,
                },
              ];
            }
            this.pay.type_now = data.pay_type_now;
            this.pay.name = data.pay_type_now == 1 ? "在线支付" : "货到付款";
            this.pay.id = data.pay_type_now;
            if (data.pay_type == 2 && data.pay_type_now != 1) {
              this.pay.index = 1;
            }
            //判断是否为主账号
            if (data.zi_list) {
              this.childList = data.zi_list;
              this.child.name = data.zi_list[0].nickname;
            }
            //账期
            this.overdue = {
              overdue_status: data.overdue_status,
              info:
                data.overdue_status == 1
                  ? `当前用户账期（${data.overdue_days_now}天），已达到账期提醒预设（${data.warn_days}天）！`
                  : data.overdue_status == 2
                  ? `当前用户账期（${data.overdue_days_now}天），已超过预设最高账期（${data.warn_days}天）无法下单！`
                  : "",
            };
            //信用金
            this.credit = {
              credit_status: data.credit_status,
              info:
                data.credit_status == 1
                  ? `当前用户欠款额度（${data.credit_now}），已达到提醒预设比例（${data.credit_notice}）！`
                  : data.credit_status == 2
                  ? `当前用户欠款额度（${data.credit_now}）天，已达停止下单比例（${data.forbid_order}）无法下单！`
                  : "",
            };
          } else {
            this.showMask = true;
            uni.showToast({
              title: res.data.errmsg,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateBack();
            }, 1500);
          }
        }
      );
    },
    gopage() {
      uni.navigateTo({
        url: "/pages/shopcart/check_wx",
      });

      // // #ifdef H5
      // uni.navigateTo({
      // 	url: '/pages/shopcart/check_map'
      // })
      // // #endif

      // // #ifdef MP-WEIXIN || APP-PLUS
      // uni.navigateTo({
      // 	url: '/pages/shopcart/check_wx'
      // })
      // // #endif
    },

    // 选择收货地址Address
    // confirmd() {
    //   uni.navigateTo({
    //     url: "/pages/address/index",
    //   });
    // },
    //筛选商品、积分商品
    filterGoods(datas) {
      let goodsList = [],
        pointList = [];
      datas.map((item) => {
        if (item.datum_activity === "积分") {
          pointList.push(item);
        } else {
          goodsList.push(item);
        }
      });
      this.pointList = pointList;
      this.goodsList = goodsList;
    },
    //根据列表、id查到对应优惠券
    findCoupon(id, isfirst) {
      let list = this.couponInfo.coupons_list;
      for (let a in list) {
        if (list[a].id === id) {
          Object.assign(this.couponInfo, {
            coupon_now: list[a],
            coup_id: id,
          });
          break;
        }
      }
      if (!isfirst) {
        this.getNewPrice();
      }
    },
    //去选择优惠券
    toChooseCoupon() {
      setTimeout((res) => {
        uni.$emit("getSubOrdCou", {
          couponInfo: this.couponInfo,
        });
      }, 500);
      uni.navigateTo({
        url: "/pages/user/coupon/coupon_choose",
      });
    },
    //选择子账号
    selectChild(val) {
      this.child.name = val[0].label;
      this.child.id = val[0].value;
      let data = val[0].extra;
      this.nowSelectInfo = {
        address: data.address_name + data.detail,
        mobile: data.mobile,
        name: data.name,
        id: val[0].value == this.info.user_id ? null : val[0].value, //如果选择的是主账号，不给id
      };
      this.choseData(this.child.id);
    },

    choseData(val) {
      $https(
        "GET",
        "isWithin",
        {
          uid: val,
        },
        (res) => {
          if (res.data.errcode == 0) {
            this.quadrants_setting = res.data.data;
          } else {
            uni.showToast({
              title: res.data.errmsg,
              icon: "none",
            });
          }
        }
      );
    },

    //选择支付方式
    selectPay(e) {
      let pay = JSON.parse(JSON.stringify(this.pay));
      Object.assign(pay, {
        name: this.payList[e.detail.value].label,
        id: this.payList[e.detail.value].value,
      });
      this.pay = pay;
      this.getNewPrice();
    },
    //选择日期
    selectDate(val) {
      this.sendDate = val.detail.value;
    },
    //选择时间
    selectTime(val) {
      this.sendTimeId = val[0].value;
      this.sendTimeName = val[0].label;
    },
    //更改优惠券、支付方式啥的。需要重新请求新的价格
    getNewPrice() {
      let params = {
        sub_money: this.money.sub_money,
        full_reduction_money: this.money.full_reduction_money,
        pay_type_now: this.pay.id,
        coup_id: this.couponInfo.coup_id,
      };
      $https("GET", "getCartMoneys", params, (res) => {
        if (res.data.errcode == 0) {
          let data = res.data.data;
          let obj = {
            balance: data.balance_now,
            delivery_fee: data.delivery_fee,
            discount_money: data.discount_money,
            total_money: data.total_money,
            should_money: data.should_money,
          };
          Object.assign(this.money, obj);
        } else {
          uni.showToast({
            icon: "none",
            title: "网络开小差了",
          });
        }
      });
    },
    tomorrow(backday) {
      var now = new Date();
      //是否是设定开始日期。按请求数据回退
      if (backday) {
        now.setTime(now.getTime() - (backday - 1) * 24 * 60 * 60 * 1000);
      } else {
        now.setTime(now.getTime() + 24 * 60 * 60 * 1000);
      }
      var tom = `${now.getFullYear()}-${
        now.getMonth() + 1 < 10
          ? "0" + (now.getMonth() + 1)
          : now.getMonth() + 1
      }-${now.getDate() < 10 ? "0" + now.getDate() : now.getDate()}`;
      return tom;
    },
    leftClick() {
      // #ifdef H5
      window.history.back(-1);
      // #endif
      // #ifndef H5
      uni.navigateBack();
      // #endif
    },
    //备注
    noteAction(e) {
      this.note = e.detail.value;
    },
    //展开
    expendList(flag, num, length) {
      this[flag] = !this[flag];
      if (this[flag]) {
        this[num] = length;
      } else {
        this[num] = 1;
      }
      // this.isexpend = !this.isexpend;
      // if(this.isexpend){
      // 	this.goodsListNum = this.goodsList.length;
      // }else{
      // 	this.goodsListNum = 1;
      // }
    },
    loadCity(longitude, latitude, key) {
      return new Promise((resolve, reject) => {
        let url = "https://apis.map.qq.com/ws/geocoder/v1/";
        jsonp(url, {
          key: key,
          location: latitude + "," + longitude,
          output: "jsonp",
        }).then((res) => {
          console.log("jsonp", res);
          if (res.status == 0) {
            resolve(res.result.address_component);
          }
        });
      });
    },
    submit() {
      // #ifdef APP-PLUS
      // if(this.pay.name == '在线支付'){
      // 	uni.showToast({
      // 		icon:'none',
      // 		title:'很抱歉！APP暂时不支持在线支付。'
      // 	})
      // 	return;
      // }
      // #endif
      if (
        this.pay.name == "货到付款" &&
        this.credit.credit_status == 2 &&
        this.overdue.overdue_status == 2
      ) {
        uni.showToast({
          title: "禁止下单",
          icon: "none",
        });
        return;
      }

      if (Number(this.money.should_money) < Number(this.money.starting_price)) {
        uni.showToast({
          title: "下单金额小于起送价",
          icon: "none",
        });
        return;
      }
      // let goodsIds = this.goodsId.map(item => item.id)
      var option = {
        cart_ids: this.goodsId,
        send_time: this.sendDate,
        send_time_id: this.sendTimeId,
        is_prior_payment: this.pay.id,
      };
      // #ifdef MP-WEIXIN
      Object.assign(option, {
        from: 2,
      });
      // #endif
      // #ifdef H5
      Object.assign(option, {
        from: 1,
      });
      // #endif
      this.nowSelectInfo.id &&
        Object.assign(option, {
          zid: this.nowSelectInfo.id,
        });
      this.couponInfo.coup_id &&
        Object.assign(option, {
          coup_id: this.couponInfo.coup_id,
        });
      if (this.note) {
        Object.assign(option, {
          remark: this.note,
        });
      }
      let key = "DVOBZ-IUQ6I-CKJGL-55SXL-77EC5-RKBVZ";
      this.loadCity("115.85817", "28.68268", key).then((res) => {
        let { province, city, district } = res;
        Object.assign(option, {
          province,
          city,
          district,
        });
        $https(
          "POST",
          `addOrder?company_id=${this.companyInfo.supplier_id}`,
          option,
          (res) => {
            if (res.data.errcode == 0) {
              if (this.pay.id == 0) {
                //货到付款
                uni.showToast({
                  title: "提交成功",
                  icon: "success",
                  success: () => {
                    setTimeout(() => {
                      uni.switchTab({
                        url: "/pages/tabar/order",
                      });
                      app.globalData.tabIndex = 0;
                      let id = app.globalData.tabIndex;
                      uni.$emit("updateorder", {
                        id: id,
                      });
                    }, 2000);
                  },
                });
              } else {
                //在线支付
                uni.redirectTo({
                  url: `/pages/shopcart/pay_for?id=${res.data.data.id}`,
                });
              }
            } else {
              uni.showToast({
                title: res.data.errmsg,
                icon: "none",
              });
            }
          }
        );
      });
    },
    //修改地址
    editAdd() {
      if (this.nowSelectInfo.id) {
        uni.navigateTo({
          url: `/pages/user/change/edit_address?zid=${this.nowSelectInfo.id}`,
        });
      } else {
        uni.navigateTo({
          url: `/pages/user/change/edit_address`,
        });
      }
      // if(!this.nowSelectInfo.id){
      // uni.navigateTo({
      // 	url:`/pages/user/change/edit_address?address=${this.info.address}&name=${this.info.name}&tel=${this.info.mobile}`
      // })
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.submit_order {
  background: #f8f9fa;

  .status_bar {
    position: fixed;
    top: 0;
  }

  .top_title {
    position: fixed;
    width: 100%;
    // #ifndef MP-WEIXIN
    top: calc(var(--status-bar-height));
    // #endif
    // #ifdef MP-WEIXIN
    top: 0;
    // #endif
    background: rgb(255, 255, 255);
    align-items: center;
    height: 100rpx;
    padding: 0 30rpx;
    z-index: 100;
    // border-bottom: 1rpx solid #e1e1e1;

    .custom-icon {
      font-size: 36rpx;
      color: #191919;
      margin-right: 36rpx;
      font-weight: 600;
    }

    .name {
      margin-left: 200rpx;
      font-size: 36rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #01000d;
    }

    .icon_user {
      width: 26rpx;
      height: 30rpx;
    }

    .icon_right {
      width: 12rpx;
      height: 16rpx;
      margin-left: 10rpx;
    }

    .account {
      margin-left: 10rpx;
    }
  }

  /deep/.u-calendar {
    background: #fff;
    padding-top: 10rpx;
  }

  .child {
    padding: 28rpx 34rpx;
  }

  .caution {
    background: #f6e8e5;

    .tip {
      color: #fe5324;
    }
  }

  .location {
    width: 30rpx;
    height: 36rpx;
    margin-right: 24rpx;
    margin-top: 5rpx;
  }

  .goods {
    // color: #191919;
    // width: 690rpx;
    // height: 1000px;
    background: #ffffff;
    border-radius: 20rpx;
    margin: 20rpx 30rpx 0 30rpx;
    .tit {
      font-size: 32rpx;
      margin: 30rpx;
    }

    .info-shop {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      margin-left: 20rpx;
      padding-top: 20rpx;
      &-logo {
        width: 30rpx;
        height: 30rpx;
        border-radius: 50%;
        image {
          width: 100%;
          height: 100%;
        }
      }
      &-title {
        margin-left: 18rpx;
        font-size: 30rpx;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      &-icon {
        width: 28rpx;
        height: 28rpx;
        background-image: url("@/static/images/right.png");
        background-size: 100% 100%;
        margin-left: 13rpx;
      }
    }

    .line {
      width: 640rpx;
      height: 1rpx;
      margin: 20rpx auto 0;
      background: #ececec;
    }

    .goodsList {
      margin: 0 0 0 10rpx;
      font-size: 28rpx;
      // border-bottom: 2rpx solid #e7e8e8;

      .list {
        margin-bottom: 20rpx;

        .imgs {
          width: 100rpx;
          height: 100rpx;
          margin-right: 30rpx;
          position: relative;

          .logo {
            width: 40rpx;
            height: 40rpx;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
          }

          .img {
            width: 100rpx;
            max-height: 100rpx;
          }
        }

        .info {
          .red {
            color: #e84b4b;
            margin-right: 10rpx;
          }

          .red_tag {
            display: inline-block;
          }

          .yellow_tag {
            font-size: 20rpx;
            padding: 2rpx 12rpx;
            background: #ff9900;
            border-radius: 6rpx;
            color: #fff;
          }

          .spu {
            margin-left: 20rpx;
            padding: 0 8rpx;
            background: #e3e3e3;
            border-radius: 8rpx;
            font-size: 16rpx;
          }
        }
      }

      .info-list {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        width: calc(100% - 30rpx);
        padding: 0 15rpx;
        &-image {
          width: 130rpx;
          height: 130rpx;
          border-radius: 16rpx;
          padding: 20rpx 20rpx 20rpx 20rpx;
          img {
            width: 100%;
            height: 100%;
            border-radius: 16rpx;
          }
        }
        .info-list-shop {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          width: 480rpx;
          padding: 20rpx 0;
          .shop-top {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            &-name {
              font-size: 24rpx;
              font-family: PingFang SC;
              font-weight: bold;
              color: #333333;
            }
          }
          .shop-meddle {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            font-size: 20rpx;
            font-family: PingFang SC;
            font-weight: bold;
            color: #999999;
            margin-top: 20rpx;
          }

          .shop-bottom {
            font-size: 24rpx;
            font-family: PingFang SC;
            font-weight: bold;
            color: #333333;
            margin-top: 20rpx;
          }
        }
      }
    }

    .flex-center {
      color: #666666;
      span {
        color: #999999;
      }
    }
  }

  .select > view {
    display: flex;
    justify-content: space-between;
  }

  .select > view view:first-child text {
    font-weight: bold;
  }

  .select > view view:last-child text {
    color: gray;
  }

  .select .remark {
    flex-direction: column;
  }

  .submit {
    height: 50px;
    position: fixed;
    bottom: 0;
    background: $white;
    justify-content: flex-end;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 1);

    .order {
      background: #40ae36;
      color: $white;
    }
  }
}

.submit_order {
  .address_info {
    // #ifndef MP-WEIXIN
    margin-top: calc(var(--status-bar-height) + 100rpx);
    // #endif
    // #ifdef MP-WEIXIN
    margin-top: 100rpx;
    // #endif
    margin: 120rpx 30rpx 20rpx 30rpx;

    // border-bottom: 16rpx solid #e7e8e8;
    // width: 690rpx;
    height: 184rpx;
    background: #ffffff;
    border-radius: 20rpx;
    display: flex;
    align-items: center;

    .caution {
      padding: 4rpx 24rpx;

      .tip {
        margin-right: 12rpx;
      }
    }

    .address > view {
      margin-bottom: 4rpx;
    }
  }

  .select {
    margin-top: 40rpx;
    padding-bottom: 1rpx;
    // margin-bottom: 20rpx;

    .remark textarea {
      margin-top: 14rpx;
    }
  }

  .select > view {
    margin-bottom: 48rpx;
  }

  .submit {
    height: 134rpx;
    width: 100%;
    padding: 0 44rpx;
    z-index: 10;

    .order {
      padding: 20rpx 46rpx;
      border-radius: 40rpx;
      margin-left: 42rpx;
    }
  }
}

.submit_order {
  // color: #191919;

  .address_info {
    background: #ffffff;
    border-radius: 20px;

    .address {
      color: #191919;
      font-size: 32rpx;

      .name {
        margin: 12rpx 0;
      }

      .caution {
        padding: 8rpx 20rpx;
        font-size: 24rpx;
        margin: 0;
      }
    }
  }

  .remark {
    margin: 20rpx 30rpx 0 30rpx;
    padding: 30rpx 30rpx 30rpx 30rpx;
    // width: 690rpx;
    height: 300rpx;
    background: #ffffff;
    border-radius: 20rpx;
    position: relative;

    span {
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #333333;
    }

    textarea {
      margin-top: 10rpx;
      width: 100%;
      font-size: 24rpx;
      min-height: 200rpx;
    }
  }

  .infomation {
    position: fixed;
    bottom: 134rpx;
    left: 0;
    right: 0;
    color: #fff;
    font-size: 10px;

    .info {
      padding-left: 20rpx;
      background: #fea85f;

      &.error {
        background: #e74c4a;
      }
    }
  }
}

.name_flex {
  display: flex;
  align-items: center;
}
</style>